
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 11/10/2011 01:40:26
-- Generated from EDMX file: C:\Users\Jordan\Documents\Visual Studio 2010\Websites\LigneDuBlanc\App_Code\LigneDublancBDD.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [LigneDuBlanc];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Commande_Client]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Commande] DROP CONSTRAINT [FK_Commande_Client];
GO
IF OBJECT_ID(N'[dbo].[FK_Detail_Commande]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Detail] DROP CONSTRAINT [FK_Detail_Commande];
GO
IF OBJECT_ID(N'[dbo].[FK_Detail_Produit]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Detail] DROP CONSTRAINT [FK_Detail_Produit];
GO
IF OBJECT_ID(N'[dbo].[FK_Produit_Collaborateur]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Produit] DROP CONSTRAINT [FK_Produit_Collaborateur];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Client]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Client];
GO
IF OBJECT_ID(N'[dbo].[Collaborateur]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Collaborateur];
GO
IF OBJECT_ID(N'[dbo].[Commande]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Commande];
GO
IF OBJECT_ID(N'[dbo].[Detail]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Detail];
GO
IF OBJECT_ID(N'[dbo].[Produit]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Produit];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Client'
CREATE TABLE [dbo].[Client] (
    [Id_client] int IDENTITY(1,1) NOT NULL,
    [Prenom] nvarchar(50)  NOT NULL,
    [Nom] nvarchar(50)  NOT NULL,
    [Adresse] nvarchar(max)  NOT NULL,
    [Code_Postal] int  NOT NULL,
    [Mail] nvarchar(50)  NOT NULL,
    [Ville] nvarchar(50)  NOT NULL,
    [Tel_fixe] int  NOT NULL,
    [Tel_mobile] int  NOT NULL,
    [Sexe] nchar(10)  NOT NULL
);
GO

-- Creating table 'Collaborateur'
CREATE TABLE [dbo].[Collaborateur] (
    [Id_collaborateur] int IDENTITY(1,1) NOT NULL,
    [Nom] nchar(10)  NOT NULL
);
GO

-- Creating table 'Commande'
CREATE TABLE [dbo].[Commande] (
    [Id_commande] int IDENTITY(1,1) NOT NULL,
    [Date_commande] datetime  NOT NULL,
    [Montant_Commande] real  NOT NULL,
    [Fk_IdClient] int  NOT NULL,
    [Prix] float  NULL
);
GO

-- Creating table 'Detail'
CREATE TABLE [dbo].[Detail] (
    [DetailID] int  NOT NULL,
    [QuantiteCommande] int  NOT NULL,
    [CommandeID_ref] int  NOT NULL,
    [ProduitID_ref] int  NOT NULL
);
GO

-- Creating table 'Produit'
CREATE TABLE [dbo].[Produit] (
    [Id_produit] int IDENTITY(1,1) NOT NULL,
    [Libelle] nvarchar(50)  NOT NULL,
    [CollaborateurID_ref] int  NOT NULL,
    [Quantite] int  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id_client] in table 'Client'
ALTER TABLE [dbo].[Client]
ADD CONSTRAINT [PK_Client]
    PRIMARY KEY CLUSTERED ([Id_client] ASC);
GO

-- Creating primary key on [Id_collaborateur] in table 'Collaborateur'
ALTER TABLE [dbo].[Collaborateur]
ADD CONSTRAINT [PK_Collaborateur]
    PRIMARY KEY CLUSTERED ([Id_collaborateur] ASC);
GO

-- Creating primary key on [Id_commande] in table 'Commande'
ALTER TABLE [dbo].[Commande]
ADD CONSTRAINT [PK_Commande]
    PRIMARY KEY CLUSTERED ([Id_commande] ASC);
GO

-- Creating primary key on [DetailID] in table 'Detail'
ALTER TABLE [dbo].[Detail]
ADD CONSTRAINT [PK_Detail]
    PRIMARY KEY CLUSTERED ([DetailID] ASC);
GO

-- Creating primary key on [Id_produit] in table 'Produit'
ALTER TABLE [dbo].[Produit]
ADD CONSTRAINT [PK_Produit]
    PRIMARY KEY CLUSTERED ([Id_produit] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Fk_IdClient] in table 'Commande'
ALTER TABLE [dbo].[Commande]
ADD CONSTRAINT [FK_Commande_Client]
    FOREIGN KEY ([Fk_IdClient])
    REFERENCES [dbo].[Client]
        ([Id_client])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Commande_Client'
CREATE INDEX [IX_FK_Commande_Client]
ON [dbo].[Commande]
    ([Fk_IdClient]);
GO

-- Creating foreign key on [CollaborateurID_ref] in table 'Produit'
ALTER TABLE [dbo].[Produit]
ADD CONSTRAINT [FK_Produit_Collaborateur]
    FOREIGN KEY ([CollaborateurID_ref])
    REFERENCES [dbo].[Collaborateur]
        ([Id_collaborateur])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Produit_Collaborateur'
CREATE INDEX [IX_FK_Produit_Collaborateur]
ON [dbo].[Produit]
    ([CollaborateurID_ref]);
GO

-- Creating foreign key on [CommandeID_ref] in table 'Detail'
ALTER TABLE [dbo].[Detail]
ADD CONSTRAINT [FK_Detail_Commande]
    FOREIGN KEY ([CommandeID_ref])
    REFERENCES [dbo].[Commande]
        ([Id_commande])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Detail_Commande'
CREATE INDEX [IX_FK_Detail_Commande]
ON [dbo].[Detail]
    ([CommandeID_ref]);
GO

-- Creating foreign key on [ProduitID_ref] in table 'Detail'
ALTER TABLE [dbo].[Detail]
ADD CONSTRAINT [FK_Detail_Produit]
    FOREIGN KEY ([ProduitID_ref])
    REFERENCES [dbo].[Produit]
        ([Id_produit])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Detail_Produit'
CREATE INDEX [IX_FK_Detail_Produit]
ON [dbo].[Detail]
    ([ProduitID_ref]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------